
#pragma used+
sfrb PINB=3;
sfrb DDRB=4;
sfrb PORTB=5;
sfrb PINC=6;
sfrb DDRC=7;
sfrb PORTC=8;
sfrb PIND=9;
sfrb DDRD=0xa;
sfrb PORTD=0xb;
sfrb TIFR0=0x15;
sfrb TIFR1=0x16;
sfrb TIFR2=0x17;
sfrb PCIFR=0x1b;
sfrb EIFR=0x1c;
sfrb EIMSK=0x1d;
sfrb GPIOR0=0x1e;
sfrb EECR=0x1f;
sfrb EEDR=0x20;
sfrb EEARL=0x21;
sfrb EEARH=0x22;
sfrw EEAR=0x21;   
sfrb GTCCR=0x23;
sfrb TCCR0A=0x24;
sfrb TCCR0B=0x25;
sfrb TCNT0=0x26;
sfrb OCR0A=0x27;
sfrb OCR0B=0x28;
sfrb GPIOR1=0x2a;
sfrb GPIOR2=0x2b;
sfrb SPCR=0x2c;
sfrb SPSR=0x2d;
sfrb SPDR=0x2e;
sfrb ACSR=0x30;
sfrb SMCR=0x33;
sfrb MCUSR=0x34;
sfrb MCUCR=0x35;
sfrb SPMCSR=0x37;
sfrb SPL=0x3d;
sfrb SPH=0x3e;
sfrb SREG=0x3f;
#pragma used-

#asm
	#ifndef __SLEEP_DEFINED__
	#define __SLEEP_DEFINED__
	.EQU __se_bit=0x01
	.EQU __sm_mask=0x0E
	.EQU __sm_adc_noise_red=0x02
	.EQU __sm_powerdown=0x04
	.EQU __sm_powersave=0x06
	.EQU __sm_standby=0x0C
	.SET power_ctrl_reg=smcr
	#endif
#endasm

extern void extern_int_set(unsigned char num,unsigned char en,unsigned char mode);

extern void timer0_set(unsigned char ms);

extern void uart_set(unsigned char uart_en,unsigned char uart_int_en,unsigned char baud);

#pragma used+

void delay_us(unsigned int n);
void delay_ms(unsigned int n);

#pragma used-

extern void SEI(void);	

extern void CLI(void); 

extern void ENTER_CRITICAL(void);

extern void EXIT_CRITICAL(void); 

extern void open_led(void);	

extern void close_led(void);	

extern void toggle_led(void);	

typedef struct S_RF_SETTINGS {
unsigned char FSCTRL1; 
unsigned char FSCTRL0; 
unsigned char FREQ2; 
unsigned char FREQ1; 
unsigned char FREQ0; 
unsigned char MDMCFG4; 
unsigned char MDMCFG3; 
unsigned char MDMCFG2; 
unsigned char MDMCFG1; 
unsigned char MDMCFG0; 
unsigned char CHANNR; 
unsigned char DEVIATN; 
unsigned char FREND1; 
unsigned char FREND0; 
unsigned char MCSM0; 
unsigned char FOCCFG; 
unsigned char BSCFG; 
unsigned char AGCCTRL2; 
unsigned char AGCCTRL1; 
unsigned char AGCCTRL0; 
unsigned char FSCAL3; 
unsigned char FSCAL2; 
unsigned char FSCAL1; 
unsigned char FSCAL0; 
unsigned char FSTEST; 
unsigned char TEST2; 
unsigned char TEST1; 
unsigned char TEST0; 
unsigned char FIFOTHR; 
unsigned char IOCFG2; 
unsigned char IOCFG0; 
unsigned char PKTCTRL1; 
unsigned char PKTCTRL0; 
unsigned char ADDR; 
unsigned char PKTLEN; 
} RF_SETTINGS;

extern void CS(void); 
extern void DCS(void); 

extern unsigned char cc_send_read(unsigned char sdata); 

extern void cc1100_init(unsigned char freq,unsigned char ch, unsigned char mode, unsigned char white,
unsigned char packet_limit); 

extern void rf_send_packet(unsigned char *txBuffer, unsigned char size);

extern unsigned char rf_receive_packet(unsigned char *rxBuffer,
unsigned char *length);

extern void rf_change_tx_power(unsigned char power);

extern void rf_change_channel(unsigned char ch); 

extern void start_receive(void);

extern void rf_idle(void);

extern void flush_rx_fifo(void);

extern void base_freq_cw_test(void); 

typedef struct {
unsigned short fifo_depth;
unsigned short fifo_read_point;
unsigned short fifo_write_point;
unsigned short fifo_used;
unsigned char   *fifo_data;
} FIFO_STRUCT;

extern void ENTER_CRITICAL(); 
extern void EXIT_CRITICAL(); 

void FIFO_init(FIFO_STRUCT *fifo); 
void FIFO_flush(FIFO_STRUCT *fifo);
unsigned char FIFO_read(FIFO_STRUCT *fifo, unsigned char   *data);
unsigned char FIFO_write(FIFO_STRUCT *fifo, unsigned char   *data);
unsigned short FIFO_get_free_size(FIFO_STRUCT *fifo);
unsigned short FIFO_get_used_size(FIFO_STRUCT *fifo);

volatile static unsigned char intc_stat = 0;

void SEI(void){
#asm("sei")
intc_stat = 1;
}

void CLI(void){
#asm("cli")
intc_stat = 0;
}

void ENTER_CRITICAL(void){
#asm("cli")
}

void EXIT_CRITICAL(void){
if(1 == intc_stat)
{
#asm("sei")
}
}

void open_led(void){

PORTD.4 = 0;
}

void close_led(void){

PORTD.4 = 1;
}

void toggle_led(void){

if(PIND.4 == 1)
{
PORTD.4 = 0;
}else{
PORTD.4 = 1;
}

}

